//
//  PTStuLifeServiceHeaderView.m
//  PlanTech
//
//  Created by ruifeng song on 2018/7/10.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "PTStuLifeServiceHeaderView.h"
#import "PTStuLifeServiceTopButton.h"

@implementation PTStuLifeServiceHeaderView

-(instancetype)initWithFrame:(CGRect)frame titleArray:(NSArray *)titleArray
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
    
        CGFloat buttonW = frame.size.width /(titleArray.count);
        
        for (int i =0; i<titleArray.count; i++) {
            
            PTStuLifeServiceTopButton * topButton = [[PTStuLifeServiceTopButton alloc]initButtonWithImage:nil btnTitle:titleArray[i]];
            [topButton setFrame:CGRectMake((i *buttonW),(frame.size.height - 20)/2,buttonW, 20)];
            topButton.btnLabel.frame  = CGRectMake(0, 0, buttonW,20);
            topButton.btnLabel.font = PTFONT_15;
            topButton.tag = i;
            [topButton addTarget:self action:@selector(onClickMenuItem:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:topButton];
        }
    
    }
    return self;
}

-(void)onClickMenuItem:(UIButton *)sender
{
    if (self.delegate) {
        [self.delegate didSelectedHeaderMenuItemIndex:sender.tag];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
